package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.dao.SysAdminRoleRelationMapper;
import com.xmall.auth.entity.SysAdminRoleRelation;
import com.xmall.auth.service.ISysAdminRoleRelationService;
import com.xmall.common.config.PlatformContant;
import com.xmall.common.config.PojoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台用户和角色关系表 服务实现类
 * </p>
 *
 * @author liuzh
 * @since 2020-06-14
 */
@Service
public class SysAdminRoleRelationServiceImpl extends ServiceImpl<SysAdminRoleRelationMapper, SysAdminRoleRelation> implements ISysAdminRoleRelationService {
    @Autowired
    SysAdminRoleRelationMapper sysAdminRoleRelationMapper;

    @Override
    public boolean saveSysAdminRoleRelation(SysAdminRoleRelation sysAdminRoleRelation) {
        PojoUtils.setSysProperties(sysAdminRoleRelation, PlatformContant.OpType.insert);
        return save(sysAdminRoleRelation);
    }

    @Override
    public boolean updateSysAdminRoleRelation(Long id, SysAdminRoleRelation sysAdminRoleRelation) {
        SysAdminRoleRelation oldSysAdminRoleRelation = getById(id);
        BeanUtils.copyProperties(sysAdminRoleRelation, oldSysAdminRoleRelation);
        PojoUtils.setSysProperties(oldSysAdminRoleRelation, PlatformContant.OpType.update);
        boolean update = update(
                oldSysAdminRoleRelation,
                new QueryWrapper<SysAdminRoleRelation>()
                        .lambda().eq(SysAdminRoleRelation::getId, id)
        );
        return update;
    }

    @Override
    public boolean deleteSysAdminRoleRelation(Long id) {
        boolean b = removeById(id);
        return b;
    }

    @Override
    public SysAdminRoleRelation getSysAdminRoleRelation(Long id) {
        SysAdminRoleRelation sysAdminRoleRelation = getById(id);
        return sysAdminRoleRelation;
    }
}
